#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
template <typename T>
void squareArray(vector<T>& v,vector<T>& tem){
    int low=0,high=v.size()-1,k=v.size()-1;
    while(low<=high){
        if(v[low]*v[low]<=v[high]*v[high]){
            tem[k--]=v[high]*v[high];
            high--;
        }else{
            tem[k--]=v[low]*v[low];
            low++;
        }
    }
}

template<typename T>
void prints(vector<T>& v){
    for_each(v.begin(),v.end(),[](T num){
        cout<<num<<" ";
    });
    cout<<endl;
}

int main(){
    vector<int> v={-4,-1,0,3,10};
    vector<int> tem(v.size(),0);
    squareArray(v,tem);
    prints(tem);
    return 0;
}